/**
 * 
 */
package hb_Teach_InitObject06_03ListTest;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

/**
 * @author Jiang Zhiyan
 *
 * 2021年6月3日 上午11:39:41
 */
public class ListTest {
	
	public List<Apple> initData() {
		List<Apple> apps = new ArrayList<Apple>();
		apps.add(new Apple("绿色", 150, "山西"));
		apps.add(new Apple("绿色", 100, "山西"));
		apps.add(new Apple("绿色", 90, "山西"));
		apps.add(new Apple("红色", 150, "山西"));
		apps.add(new Apple("红色", 100, "山西"));
		apps.add(new Apple("红色", 90, "山西"));
		apps.add(new Apple("绿色", 150, "陕西"));
		apps.add(new Apple("绿色", 100, "陕西"));
		apps.add(new Apple("绿色", 90, "陕西"));
		apps.add(new Apple("红色", 150, "陕西"));
		apps.add(new Apple("红色", 100, "陕西"));
		apps.add(new Apple("红色", 90, "陕西"));
		apps.add(new Apple("绿色", 150, "陕西"));

		apps.add(new Apple("绿色", 100, "新疆"));
		apps.add(new Apple("绿色", 90, "新疆"));
		apps.add(new Apple("红色", 150, "新疆"));
		apps.add(new Apple("红色", 100, "新疆"));
		apps.add(new Apple("红色", 90, "新疆"));
		return apps;
	}

	@Test
	public void testApple() {
		List<Apple> datas = initData();
		int num=0;
		// 1. 获得所有的红苹果
		System.out.println("获得所有的红苹果:");
          for(int i=0;i<datas.size();i++) {
        	 if(datas.get(i).getColor().equals("红色")) {
        		 System.out.println(datas.get(i).getColor()+","+datas.get(i).getLocation()+","+datas.get(i).getWeight());
        	     num++;
        	     datas.set(num-1, datas.get(i));
        	     continue;
        	 }	
          }
         
//          检验
//          System.out.println("-----");
//          for(int i=0;i<num;i++) {
//        	  System.out.println(datas.get(i).getColor()+","+datas.get(i).getLocation()+","+datas.get(i).getWeight());
//          }
          int cnt=0;
          System.out.println(num+","+datas.size());
		// 2. 获得所有的重量超过100g的红苹果
          System.out.println("\n获得所有的重量超过100g的红苹果:");
          for(int i=0;i<num;i++) {
             if(datas.get(i).getWeight()>=100) {
            	 System.out.println(datas.get(i).getColor()+","+datas.get(i).getLocation()+","+datas.get(i).getWeight());
        	     cnt++;
        	     datas.set(cnt-1, datas.get(i));
        	     continue;
          }    
          }
		// 3. 获得陕西或者陕西重量超过100g的红苹果
          System.out.println("获得陕西或者陕西重量超过100g的红苹果:");
          for(int i=0;i<cnt;i++) {
        	  if(datas.get(i).getWeight()>=100&&(datas.get(i).getLocation().equals("陕西")||datas.get(i).getLocation().equals("山西"))) {
             	 System.out.println(datas.get(i).getColor()+","+datas.get(i).getLocation()+","+datas.get(i).getWeight());
         	     } 
          }
	}
}
